#include "wm/shell/app_list.h"

#include "ash/shell.h"
#include "base/i18n/case_conversion.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "ui/app_list/search_box_model.h"
#include "ui/app_list/search_result.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font.h"
#include "ui/gfx/image/image_skia.h"

namespace wm {
namespace shell {

namespace {

// LauncherItem is an app item of app list.
class LauncherItem : public app_list::AppListItemModel {
 public:
  explicit LauncherItem() {
/*    SetIcon(GetIcon(type));
    SetTitle(GetTitle(type));
 */ }
/*
  static gfx::ImageSkia GetIcon(Type type) {
  }

  // The text below is not localized as this is an example code.
  static std::string GetTitle(Type type) {
  }

  // The text below is not localized as this is an example code.
  static std::string GetDetails(Type type) {
  }
*/

  void Activate(int event_flags) {
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(LauncherItem);
};

}  // namespace

XdgAppListViewDelegate::XdgAppListViewDelegate() : model_(NULL) {
}

XdgAppListViewDelegate::~XdgAppListViewDelegate() {
}

void XdgAppListViewDelegate::PopulateApps(app_list::AppListModel::Apps* apps) {
}

gfx::ImageSkia XdgAppListViewDelegate::CreateSearchBoxIcon() {
  const string16 icon_text = ASCIIToUTF16("ash");
  const gfx::Size icon_size(32, 32);

  gfx::Canvas canvas(icon_size, ui::SCALE_FACTOR_100P,
                     false /* is_opaque */);
  canvas.DrawStringInt(icon_text,
                       gfx::Font(),
                       SK_ColorBLACK,
                       0, 0, icon_size.width(), icon_size.height(),
                       gfx::Canvas::TEXT_ALIGN_CENTER |
                           gfx::Canvas::NO_SUBPIXEL_RENDERING);

  return gfx::ImageSkia(canvas.ExtractImageRep());
}

void XdgAppListViewDelegate::DecorateSearchBox(
    app_list::SearchBoxModel* search_box_model) {
  search_box_model->SetIcon(CreateSearchBoxIcon());
  search_box_model->SetHintText(ASCIIToUTF16("Type to search..."));
}

// Overridden from ash::AppListViewDelegate:
void XdgAppListViewDelegate::SetModel(app_list::AppListModel* model) {
  model_ = model;
  PopulateApps(model_->apps());
  DecorateSearchBox(model_->search_box());
}

app_list::SigninDelegate* XdgAppListViewDelegate::GetSigninDelegate() {
  return NULL;
}

void XdgAppListViewDelegate::ActivateAppListItem(
    app_list::AppListItemModel* item,
    int event_flags) {
}

void XdgAppListViewDelegate::OpenSearchResult(
    const app_list::SearchResult& result,
    int event_flags) {
  NOTIMPLEMENTED();
}

void XdgAppListViewDelegate::InvokeSearchResultAction(
    const app_list::SearchResult& result,
    int action_index,
    int event_flags) {
  NOTIMPLEMENTED();
}

void XdgAppListViewDelegate::StartSearch() {
  string16 query;
  TrimWhitespace(model_->search_box()->text(), TRIM_ALL, &query);
  query = base::i18n::ToLower(query);

  model_->results()->DeleteAll();
  if (query.empty())
    return;
}

void XdgAppListViewDelegate::StopSearch() {
  // Nothing needs to be done.
}

void XdgAppListViewDelegate::Dismiss() {
  DCHECK(ash::Shell::HasInstance());
  if (ash::Shell::GetInstance()->GetAppListTargetVisibility())
    ash::Shell::GetInstance()->ToggleAppList(NULL);
}

void XdgAppListViewDelegate::ViewClosing() {
  // Nothing needs to be done.
}

void XdgAppListViewDelegate::ViewActivationChanged(bool active) {
  // Nothing needs to be done.
}

gfx::ImageSkia XdgAppListViewDelegate::GetWindowIcon() {
  return gfx::ImageSkia();
}

}  // namespace shell
}  // namespace wm

